package com.sinosun.autotestmachine;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;


/**
 * 测试结果列表适配器
 * @author HYW
 *
 */
public class ItemAdapter extends BaseAdapter {
	
	List<Element> content = null;
	Context ctx;
	
	public ItemAdapter(Context context, List<Element> content) {
		this.ctx = context;
		this.content = content;
	}

	@Override public int getCount() {
		if (content == null) {
			return 0;
		}
		return content.size();
	}

	@Override public Object getItem(int position) {
		return content.get(position);
	}

	@Override public long getItemId(int position) {
		return position;
	}

	@Override public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(ctx).inflate(R.layout.item_layout, null);
			holder.item = (TextView) convertView.findViewById(R.id.item);
			convertView.setTag(holder);
		} else {
			holder = (Holder)convertView.getTag();
		}
		
		if (content.get(position).getEndFlag()) {
			holder.item.setText(content.get(position).getEleStr());
		} else {
			holder.item.setText(content.get(position).getEleStr() + "\n。。。。。。");
		}
		
		if (content.get(position).getEleFlag() == 0) {
			holder.item.setTextColor(Color.BLACK);
		} else {
			holder.item.setTextColor(Color.RED);
		}
		return convertView;
	}
	
	class Holder {
		TextView item;
	}

}
